#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <map>

using namespace std;

#define SLOPE_EDGE_SPEC(idx) (slope_edge_vec[idx])
#define VERTEX(idx) (vertex_ary[idx])
#define DELTA 0.0001

typedef struct tag_coord
{
    float x;
    float y;
} coord_t;

typedef struct tag_slope
{
    float l;
    float s;
} slope_t;

typedef struct tag_equation
{
    float k;
    float b;
    float angle;

    tag_equation():
        k(0.0f), b(0.0f), angle(0.0f)
    {
    }

    tag_equation(const float &k_a, const float &b_a, float a_a = 0.0f):
        k(k_a), b(b_a), angle(a_a)
    {
    }

    float theta()
    {
        if(angle == 0.0f)
            angle = atanf(k);

        return angle;
    }

    static tag_equation build_equation(coord_t p1, coord_t p2)
    {

    }
} equation_t;


typedef struct tag_edge_spec
{
    equation_t e;
    coord_t left_point;
    coord_t right_point;
} edge_spec_t;

int testcase_num = 0;
int vertex_num = 0;
coord_t* vertex_ary = NULL;
vector<slope_t> slope_vec;
vector<edge_spec_t> slope_edge_vec;
coord_t gravity_center;
coord_t slope_end;

coord_t get_left_point(equation_t e, coord_t right_point, slope_t s)
{
    coord_t left_point;

    return left_point;
}

bool float_equal(float v1, float v2)
{
	if(fabs(v1 - v2) <= DELTA)
	{
		return true;
	}

	return false;
}

bool can_scroll(coord_t gravity_center, coord_t point)
{
    return !float_equal(gravity_center.x, point.x);
}

bool can_scroll(coord_t gravity_center, coord_t point1, coord_t point2)
{
    coord_t left_point = point1.x > point2.x ? point2 : point1;
    coord_t right_point = point1.x > point2.x ? point1 : point2;

    return !( gravity_center.x >= left_point.x && gravity_center.x <= right_point.x);
    
}

float dist(coord_t p1, coord_t p2)
{
    float x = p1.x - p2.x;
    float y = p1.y - p2.y;
    
    return sqrtf(x * x + y * y);
}

int next_vertex(int idx)
{
    return (idx + 1) % vertex_num;
}

int prev_vertex(int idx)
{
    int tmp = idx - 1;
    tmp = tmp < 0 ? vertex_num + tmp : tmp; 
    return tmp % vertex_num;
}

bool on_edge(coord_t point, edge_spec_t edge)
{
    equation_t e = edge.e;
   
    if(float_equal( point.y, e.k * point.x + e.b))
    {
        if(point.x >= edge.left_point.x && point.x <= edge.right_point.x)
            return true;
    }
    
    return false;
}


float calc_slope(coord_t p1, coord_t p2)
{
    return fabs(p2.y - p1.y) / fabs(p1.x - p2.x);
}

float calc_intersection_angle(coord_t p1, coord_t p2, coord_t p1_, coord_t p2_)
{
    float m1 = dist(p1, p2);
    float m2 = dist(p1_, p2_);

    coord_t vec1,vec2;
    vec1.x = p2.x - p1.x;
    vec1.y = p2.y - p1.y;

    vec2.x = p2_.x - p1_.x;
    vec2.y = p2_.y - p1_.y;

    float dot_product = vec1.x * vec2.x + vec1.y * vec2.y;


    float val = dot_product / (m1 * m2); 
    return acosf(val);
}

coord_t rotate(float theta, coord_t pivot, coord_t p, bool clockwise)
{
    float c = cos(theta);
    float s = sin(theta);

    coord_t ret;

    if(!clockwise)
    {
        //x-x0=(x'-x0)cosa+(y'-y0)sina
        //y-y0=-(x'-x0)sina+(y'-y0)cosa
        ret.x = (p.x - pivot.x) * c - (p.y - pivot.y) * s + pivot.x;
        ret.y = (p.x - pivot.x) * s + (p.y - pivot.y) * c + pivot.y;
    }
    else
    {
        //x'-x0=(x-x0)cosa-(y-y0)sina
        //y'-y0=(x-x0)sina+(y-y0)cosa
        ret.x = (p.x - pivot.x) * c + (p.y - pivot.y) * s + pivot.x;
        ret.y = - (p.x - pivot.x) * s + (p.y - pivot.y) * c + pivot.y;
    }
    return ret;
}


bool point_on_edge(coord_t fall_point, edge_spec_t e)
{
    if(fall_point.x <= e.right_point.x && fall_point.x >= e.left_point.x)
    {
        return true;
    }

    return false;
}

coord_t calc_fall_point_base(coord_t point, coord_t pivot, edge_spec_t e, bool clockwise)
{
    float d = dist(point, pivot);

    coord_t fall_point;

    if(point_on_edge(pivot, e))
    {

        if(clockwise)
        {
            fall_point.x = pivot.x + cos(e.e.theta()) * d;
            fall_point.y = pivot.y + sin(e.e.theta()) * d;
        }
        else
        {
            fall_point.x = pivot.x - cos(e.e.theta()) * d;
            fall_point.y = pivot.y - sin(e.e.theta()) * d;
        }
    }
    else
    {
        //y = kx + c
        //r**2 = (x - a)**2 + (y - b)**2
        //A = k**2 + 1
        //B = 2kc - 2kb -2a
        //C = a**2 + b**2 + c**2 - 2bc - r**2

        float a = e.e.k * e.e.k + 1.0f;
        float b = 2 * e.e.k * e.e.b - 2 * e.e.k * pivot.y - 2 * pivot.x;
        float c = pivot.x * pivot.x + pivot.y * pivot.y + e.e.b * e.e.b - 2 * pivot.y * e.e.b - d * d;

        if(clockwise)
        {
            fall_point.x = (- b + sqrt(b * b - 4 * a * c)) / (2 * a);
        }
        else
        {
            fall_point.x = (- b - sqrt(b * b - 4 * a * c)) / (2 * a);
        }

        fall_point.y = e.e.k * fall_point.x + e.e.b;
    }

    return fall_point;
}
coord_t calc_fall_point(coord_t point, coord_t pivot, int edge_idx, bool clockwise)
{
    coord_t fall_point;
    int cur_edge_idx = edge_idx;
    edge_spec_t edge;

    do{
        if((clockwise && cur_edge_idx == 0) || (!clockwise && cur_edge_idx == slope_edge_vec.size() - 1))
        {
            fall_point.x = 0.0f;
            fall_point.y = 0.0f;
            break;
        }

        edge = clockwise ? SLOPE_EDGE_SPEC(cur_edge_idx--) : SLOPE_EDGE_SPEC(cur_edge_idx++);
        fall_point = calc_fall_point_base(point, pivot, edge,clockwise);
    }while(!point_on_edge(fall_point, edge));

    return fall_point;
}




void update_all_vertices(coord_t v, float angle, bool clockwise)
{
    for(int i = 0; i < vertex_num; i ++)
        vertex_ary[i] = rotate(angle, v, vertex_ary[i], clockwise);


    gravity_center = rotate(angle, v, gravity_center, clockwise);

    ////debug begin
    //FILE* fp = fopen("log.txt", "a");
    //fprintf(fp, "\n");
    //for(int i = 0; i < vertex_num; i ++)
    //{
    //	fprintf(fp, "%f %f\n", vertex_ary[i].x, vertex_ary[i].y);
    //}
    //fprintf(fp, "%f %f\n", gravity_center.x, gravity_center.y);
    //fclose(fp);
}

void do_calc()
{
    slope_edge_vec.clear(); 
    coord_t right_point;
    coord_t left_point;
    slope_t tmp;

    {
        vector<slope_t>::iterator it;

        for(it = slope_vec.begin(), right_point = slope_end; it != slope_vec.end(); it ++)
        {
            slope_t s = *it;
            float k = s.s;
            float b = right_point.y - k * right_point.x;
            equation_t e(k, b, 0.0f);
            left_point.x = right_point.x - cos(e.theta()) * s.l;
            left_point.y = right_point.y - sin(e.theta()) * s.l;

            edge_spec_t edge_spec = {e, left_point, right_point};

            slope_edge_vec.push_back(edge_spec);
            right_point = left_point;
        };
    }

    //	//debug begin
    //	FILE* fp = fopen("log.txt", "a");
    //	for(int i = 0; i < slope_edge_vec.size(); i++)
    //	{
    //		edge_spec_t e = slope_edge_vec[i];
    //		fprintf(fp, "%f %f %f %f\n", e.left_point.x, e.left_point.y, e.right_point.x, e.right_point.y);
    //	}
    //
    //
    //	fprintf(fp, "\n");
    //	for(int i = 0; i < vertex_num; i ++)
    //	{
    //		coord_t v = vertex_ary[i];
    //		fprintf(fp, "%f %f\n", v.x, v.y);
    //	}
    //
    //	fprintf(fp, "%f %f\n", gravity_center.x, gravity_center.y);
    //	fclose(fp);
    //	//debug end


    map<int, int> contact_info;//key = vertexIdx, value = edgeIdx
    while(true)
    {
        contact_info.clear();
        {
            int cnt = slope_edge_vec.size();
            for(int j = 0; j < cnt; j ++)
            {
                for(int i = 0; i < vertex_num; i ++)
                {
                    coord_t v = vertex_ary[i];

                    if(on_edge(v, SLOPE_EDGE_SPEC(j)))
                    {
                        if(contact_info.find(i) != contact_info.end())
                        {
                            edge_spec_t e =  SLOPE_EDGE_SPEC( contact_info[i] );
                            if(e.e.k < SLOPE_EDGE_SPEC(j).e.k)
                                continue;
                        }
                        contact_info[i] = j;
                    }
                }
            }
        }

        coord_t fall_point;
        if(contact_info.size() == 1)
        {
            map<int, int>::iterator it = contact_info.begin();
            int vertex_idx = it->first;
            int edge_idx = it->second;
            coord_t v = VERTEX(it->first);
            edge_spec_t e = SLOPE_EDGE_SPEC(it->second);

            coord_t left_fall_point = calc_fall_point(VERTEX(next_vertex(vertex_idx)), v, edge_idx, true);
            coord_t right_fall_point = calc_fall_point(VERTEX(prev_vertex(vertex_idx)), v, edge_idx, false);

            if(can_scroll(gravity_center, v))
            {
                if(gravity_center.x > v.x)// clockwise
                {
                    coord_t v2 = VERTEX(next_vertex(vertex_idx));
                    //it may fall on this edge or right edge
                    int cur_edge_idx = edge_idx;
                    edge_spec_t edge;
                    do
                    {
                        edge = SLOPE_EDGE_SPEC(cur_edge_idx --);                      
                        fall_point = calc_fall_point(v2, v, edge, true);
                    }while(!point_on_edge(fall_point, edge));

                    float angle = calc_intersection_angle(v, v2, v, fall_point);

                    update_all_vertices(v, angle, true);
                }
                else//gravity_center.x < v.x, anticlockwise
                {
                    coord_t v2 = VERTEX(prev_vertex(vertex_idx));

                    //it may fall on this edge or left edge
                    int cur_edge_idx = edge_idx;
                    edge_spec_t edge;
                    do
                    {
                        edge = SLOPE_EDGE_SPEC(cur_edge_idx ++);

                        fall_point = calc_fall_point(v2, v, edge, false);
                    }while(!point_on_edge(fall_point, edge));

                    float angle = calc_intersection_angle(v, v2, v, fall_point);
                    update_all_vertices(v, angle, false);
                }
            }
            else
            {
                printf("%.3f %.3f\n", gravity_center.x, gravity_center.y);
                break;
            }
        }
        else if(contact_info.size() == 2)
        {
            map<int, int>::iterator it = contact_info.begin();
            int vertex1_idx = it->first;
            int edge1_idx = it->second;

            it ++;
            int vertex2_idx = it->first;
            int edge2_idx = it->second;

            coord_t v1 = VERTEX(vertex1_idx);
            edge_spec_t e1 = SLOPE_EDGE_SPEC(edge1_idx);

            coord_t v2 = VERTEX(vertex2_idx);
            edge_spec_t e2 = SLOPE_EDGE_SPEC(edge2_idx);

            if(can_scroll(gravity_center, v1, v2))
            {
                coord_t left_v, right_v;
                edge_spec_t left_e, right_e;
                int left_v_idx, right_v_idx;
                int left_e_idx, right_e_idx; 

                if(v1.x > v2.x)
                {
                    left_v = v2;
                    right_v = v1;
                    left_v_idx = vertex2_idx;
                    right_v_idx = vertex1_idx;

                    left_e = e2;
                    right_e = e1;
                    left_e_idx = edge2_idx;
                    right_e_idx = edge1_idx;
                }
                else
                {
                    left_v = v1;
                    right_v = v2;
                    left_v_idx = vertex1_idx;
                    right_v_idx = vertex2_idx;

                    left_e = e1;
                    right_e = e2;
                    left_e_idx = edge1_idx;
                    right_e_idx = edge2_idx;
                }

                if(gravity_center.x > right_v.x)//clockwise
                {
                    coord_t v3 = VERTEX(next_vertex(right_v_idx));
                    //fall on right_e or right edge of right_e
                    int cur_edge_idx = right_e_idx;
                    edge_spec_t edge;
                    do
                    {
                        edge = SLOPE_EDGE_SPEC( cur_edge_idx--); 
                        fall_point = calc_fall_point(v3, right_v, edge, true);
                    }while(!point_on_edge(fall_point, edge));

                    float angle = calc_intersection_angle(right_v, v3, right_v, fall_point);
                    update_all_vertices(right_v, angle, true);
                }
                else//anticlockwise
                {
                    coord_t v3 = VERTEX(prev_vertex(left_v_idx));
                    //fall on left_e or left edge of left_e
                    int cur_edge_idx = left_e_idx;
                    edge_spec_t edge;
                    do
                    {
                        edge = SLOPE_EDGE_SPEC(cur_edge_idx++);
                        fall_point = calc_fall_point(v3, left_v, edge, false);
                    }while(!point_on_edge(fall_point, edge));

                    float angle = calc_intersection_angle(left_v, v3, left_v, fall_point);

                    update_all_vertices(left_v, angle, false);
                }
            }
            else
            {
                printf("%.3f %.3f\n", gravity_center.x, gravity_center.y);
                break;
            }
        }
        else
        {
            //impossible
            printf("If you saw this, something were wrong in this program!\n");
        }
    }


}

int main(void)
{
    scanf("%d", &testcase_num);

    for(int i = 0; i < testcase_num; i ++)
    {
        scanf("%d", &vertex_num);
        vertex_ary = (coord_t*)malloc(sizeof(coord_t) * vertex_num);
        for(int j = 0; j < vertex_num; j ++)
        {
            scanf("%f %f", &vertex_ary[j].x, &vertex_ary[j].y);
        }

        scanf("%f %f", &gravity_center.x, &gravity_center.y);

        slope_t tmp_slope;
        do {
            scanf("%f %f", &tmp_slope.l, &tmp_slope.s); 
            slope_vec.push_back(tmp_slope);
        } while ( tmp_slope.s );

        scanf("%f %f", &slope_end.x, &slope_end.y);

        do_calc();
    }

    free(vertex_ary), vertex_ary = NULL;
    return 0;
}
